/**
 * 记分牌类
 */
class ScorePanel {
    public score:number = 0;
    public level:number = 1;
    public readonly maxLevel: number;
    public readonly upScore: number;

    public scoreEle:HTMLElement;
    public levelEle:HTMLElement;

    constructor(maxLevel: number = 10, upScore: number = 10) {
        this.scoreEle = document.getElementById("score")
        this.levelEle = document.getElementById("level")
        this.maxLevel = maxLevel
        this.upScore = upScore
    }

    /**
     * 增加分数
     */
    addScore(){
        this.score += 1;
        this.scoreEle.innerText = this.score.toString()
        if(this.score % this.upScore === 0){
            this.upLevel();
        }
    }

    /**
     * 增加等级
     */
    upLevel(){
        if(this.level > 0 && this.level < this.maxLevel){
            this.level += 1
        }
        this.setLevelEle();
    }

    /**
     * 下降等级
     */
    downLevel(){
        this.level -= 1
        this.setLevelEle();
    }

    setLevelEle(){
        this.levelEle.innerText = this.level.toString()
    }
}


export default ScorePanel
